package com.jiuyin.dianjing.ui.activity.match;

import android.util.Pair;
import android.view.View;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;
import com.jiuyin.dianjing.R;
import com.jiuyin.dianjing.adapter.TabAdapter;
import com.jiuyin.dianjing.ui.activity.base.BaseActivity;
import com.jiuyin.dianjing.ui.fragment.match.FragmentMyMatch;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

import static com.jiuyin.dianjing.api.constant.ApiConstant.KEY_MY_MATCH;
import static com.jiuyin.dianjing.api.constant.ApiConstant.KEY_MY_MATCH1;
import static com.jiuyin.dianjing.api.constant.ApiConstant.KEY_MY_MATCH2;

/**
 * 我的赛事
 */
public class MatchMyActivity extends BaseActivity {
    protected final List<Pair<String, Fragment>> mFragments = new ArrayList<>();
    @BindView(R.id.vp_view_container)
    ViewPager mViewPager;
    @BindView(R.id.tabs)
    TabLayout mTabLayout;
    private TabAdapter mTabAdapter;

    @Override
    protected int setLayoutId() {
        return R.layout.activity_match_my;
    }

    @Override
    protected void initData() {
        addData();
    }

    @Override
    protected void initView() {
        setTitle(R.string.match_my_game);
    }

    @OnClick({R.id.iv_back})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
            default:
                break;
        }
    }

    protected void addData() {
        addFragments();
        initTabLayout();
    }

    protected void addFragments() {
        mFragments.add(Pair.create(getString(R.string.match_my_game_whole_match), FragmentMyMatch.newInstance(KEY_MY_MATCH)));
        mFragments.add(Pair.create(getString(R.string.match_my_game_my_enter), FragmentMyMatch.newInstance(KEY_MY_MATCH1)));
        mFragments.add(Pair.create(getString(R.string.match_my_game_my_create), FragmentMyMatch.newInstance(KEY_MY_MATCH2)));
    }

    protected void initTabLayout() {
        mTabAdapter = new TabAdapter(getSupportFragmentManager(), mFragments);
        mViewPager.setAdapter(mTabAdapter);
        mViewPager.setOffscreenPageLimit(mFragments.size());
        mTabLayout.setupWithViewPager(mViewPager);
    }
}
